#include "stdafx.h"
#include "link.h"
using namespace System::Runtime::InteropServices;
#ifdef _DEBUG
[DllImportAttribute("SocketCppD", CharSet = CharSet::Ansi,
	CallingConvention = CallingConvention::Cdecl)]
#else
[DllImportAttribute("SocketCpp", CharSet = CharSet::Ansi,
	CallingConvention = CallingConvention::Cdecl)]
#endif
extern "C" int OnReadFunc(int id,array<char>^ data, int len);

Clink::Clink()
{
	m_cache = gcnew String("");
	for (int i = 0; i < m_maxSize; i++) {
		m_cache = m_cache->Insert(0,"0");
	}
	m_maxSize = m_cache->Length;
}

void Clink::OnFuncStateChange(int id, int code)
{
	if (m_pFuncChange)
	{
		m_pFuncChange(id, code);
	}
};

void Clink::OnFuncReadCallBack(int id, int size)
{
	Console::WriteLine(id);
	Console::WriteLine(size);
	array<char>^ tmp = gcnew array<char>(1024);
// 	for (int i = 0; i < 1024; i++) {
// 		tmp = tmp->Insert(0, "0");
// 	}
	int len = OnReadFunc(id, tmp,1024);

	if (len > 0 && m_pFuncRead)
	{
		array<wchar_t>^ arr = gcnew array<wchar_t>(len);
		for (int i = 0; i < len; i++)
		{
			arr[i] = tmp[i];
		}
		m_pFuncRead(id, arr,len);
	}
};

